//
//  MYTabBar.swift
//  Sina
//
//  Created by 王亮龙1 on 16/5/19.
//  Copyright © 2016年 lianglong. All rights reserved.
//

import UIKit

class MYTabBar: UITabBar {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width: CGFloat = self.bounds.size.width / 5
        
        
        let rect = CGRect(x: 0, y: 0, width: width, height: self.bounds.height)
        
        var index: CGFloat = 0
        
        for subview in subviews {
            
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                subview.frame = CGRectOffset(rect, width * index, 0)
                
                index += (index == 1 ? 2 : 1)
            }
        }
        
        
//        //设置圆角
//        plusBtn.layer.cornerRadius = self.bounds.height / 2
//        plusBtn.layer.masksToBounds = true

        
        plusBtn.frame = CGRectOffset(rect, width * 2, 0)
        
        
    }
    
    
    lazy var plusBtn: UIButton = {
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState: .Highlighted)
        
        

        
        
        return btn
    }()


}
